const rule2 = require("../rule.v2");
const rule = require("../rule");
const CardBox = require("../CardBox");
const Card = require("../Card");
const Player = require("../Player");
const CARDBOX = new CardBox();
const tester = new Player("test1");

const Benchmark = require("benchmark");
const suite = new Benchmark.Suite();

var cards = "红心_2,梅花_2,方块_2,黑桃_2,梅花_3".split(",");
suite
	// .add(
	// 	"native",
	// 	deferred => {
	// 		var res_info = {};
	// 		var is_four = rule.is_four(tester.card_list, res_info);
	// 		deferred.resolve(is_four, res_info);
	// 	},
	// 	{ defer: true }
	// )
	.add(
		"edge",
		deferred => {
			var res_info = {};

			var i = 5;
			var cb =function () {
				i--;
				if (i==0) {
					deferred.resolve();
				}
			}
			rule2
				.is_four("红心_2,梅花_2,方块_2,黑桃_2,梅花_A".split(","), res_info)
				.then(is_four => {
					cb();
				});
			rule2
				.is_four("红心_2,梅花_2,方块_2,黑桃_2,梅花_A".split(","), res_info)
				.then(is_four => {
					cb();
				});
			rule2
				.is_four("红心_2,梅花_2,方块_2,黑桃_2,梅花_A".split(","), res_info)
				.then(is_four => {
					cb();
				});
			rule2
				.is_four("红心_2,梅花_2,方块_2,黑桃_2,梅花_A".split(","), res_info)
				.then(is_four => {
					cb();
				});
			rule2
				.is_four("红心_2,梅花_2,方块_2,黑桃_2,梅花_A".split(","), res_info)
				.then(is_four => {
					cb();
				});
		},
		{ defer: true }
	)
	.on("cycle", function(event) {
		console.log(String(event.target));
	})
	.on("complete", function() {
		console.log("Fastest is " + this.filter("fastest").map("name"));
	})
	.run();

// (async () => {
// 	var res_info = {};
// 	rule2
// 		.is_four("红心_2,梅花_2,方块_2,黑桃_2,梅花_A".split(","), res_info)
// 		.catch(err => {
// 			console.error("ERROR!", err);
// 		})
// 		.then(is_four => {
// 			console.log(is_four, res_info);
// 		});
// })();
